package cc.vicp.djx314.starfood.web.dish;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cc.vicp.djx314.starfood.domain.dish.Dish;
import cc.vicp.djx314.starfood.domain.dish.DishesRankKind;
import cc.vicp.djx314.starfood.service.dishes.DishesRankService;

@Controller 
public class DishesRankOfAllKindsController {
	//~属性=====================================================================
	@Autowired
	private DishesRankService dishesRankService;
	/**
	 * 输出日志的Log实例化
	 */
	private static final Logger logger = LoggerFactory.getLogger(DishesRankOfAllKindsController.class);

	//~方法=====================================================================
	@RequestMapping(value = "/dishrank/{rankkindid}", method = RequestMethod.GET)
	public String showRankDishesOfOneKind(@PathVariable("rankkindid") Integer rankKindId,
			Model model) {
		boolean isRankKindExists = false;
		try {
			isRankKindExists = dishesRankService.getRankKindForIfExists(rankKindId);
		} catch (RuntimeException e) {
			logger.info("获取菜式排名类型过程发生错误", e);
		}
		String resultView = "error/dishranknotexists";
		if (isRankKindExists == true) {
			List<Dish> dishes = dishesRankService.getDishesRankOfOneKind(rankKindId);
			model.addAttribute("dishes", dishes);
			resultView = "customer/infoshow/dishesrankofonekind";
		}
		return resultView;
	}

	@RequestMapping(value = "/dishesranks", method = RequestMethod.GET)
	public String showAllDishesRank(Model model) {
		List<DishesRankKind> dishesRankKinds = dishesRankService.getRankKinds();
		model.addAttribute("rankKinds", dishesRankKinds);
		return "customer/infoshow/alldishesrank";
	}

	//~getter和setter=====================================================================
	public void setDishesRankService(DishesRankService dishesRankService) {
		this.dishesRankService = dishesRankService;
	}
}